namespace Digitalmes.Domain;

/// <summary>
/// 表示实现类为实体。
/// </summary>
public interface IEntityBaseId
{
    /// <summary>
    /// 唯一编号
    /// </summary>
    long Id { get; set; }

    /// <summary>
    /// 实体是否为临时创建的。
    /// </summary>
    /// <returns></returns>
    bool IsTransient();
}

/// <summary>
/// 实体抽象类。
/// </summary>
public abstract class EntityBaseId : IEntityBaseId
{
    /// <summary>
    /// 唯一编号
    /// </summary>
    [SugarColumn(ColumnDescription = "Id", IsPrimaryKey = true, IsIdentity = false)]
    public long Id { get; set; }

    /// <summary>
    /// 实体是否为临时创建的。
    /// </summary>
    /// <returns></returns>
    public bool IsTransient()
    {
        return Id <= 0;
    }
}

/// <summary>
/// 带有审计的实体抽象类。
/// </summary>
public abstract class EntityBase : EntityBaseId, IAuditEntity
{
    /// <summary>
    /// 创建时间
    /// </summary>
    [SugarColumn(ColumnDescription = "创建时间")]
    public DateTime CreateTime { get; set; }

    /// <summary>
    /// 创建人
    /// </summary>
    [SugarColumn(ColumnDescription = "创建人", Length = 64)]
    public string? CreateUser { get; set; }

    /// <summary>
    /// 修改时间
    /// </summary>
    [SugarColumn(ColumnDescription = "修改时间")]
    public DateTime? UpdateTime { get; set; }

    /// <summary>
    /// 修改人
    /// </summary>
    [SugarColumn(ColumnDescription = "修改人", Length = 64)]
    public string? UpdateUser { get; set; }
}

/// <summary>
/// 带有租户的实体抽象类。
/// </summary>
public abstract class EntityTenantId : EntityBaseId, ITenantIdFilter
{
    /// <summary>
    /// 租户
    /// </summary>
    [SugarColumn(ColumnDescription = "租户")]
    public long TenantId { get; set; }
}

/// <summary>
/// 带有审计的租户实体抽象类
/// </summary>
public abstract class EntityTenantBase : EntityTenantId, IAuditEntity
{
    /// <summary>
    /// 创建时间
    /// </summary>
    [SugarColumn(ColumnDescription = "创建时间")]
    public DateTime CreateTime { get; set; }

    /// <summary>
    /// 创建人
    /// </summary>
    [SugarColumn(ColumnDescription = "创建人", Length = 64)]
    public string? CreateUser { get; set; }

    /// <summary>
    /// 修改时间
    /// </summary>
    [SugarColumn(ColumnDescription = "修改时间")]
    public DateTime? UpdateTime { get; set; }

    /// <summary>
    /// 修改人
    /// </summary>
    [SugarColumn(ColumnDescription = "修改人", Length = 64)]
    public string? UpdateUser { get; set; }
}
